/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1World;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.utils.L1SpawnUtil;

/**
 * Class <code>QuestMagicAngleFlute</code> 新50级任务 (王、骑、妖、法) 魔之角笛 - 49167.
 * 
 * @author jrwz
 * @version 2012-6-24上午01:51:13
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class QuestMagicAngleFlute extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new QuestMagicAngleFlute();
    }

    /** 新50级任务 (王、骑、妖、法) 魔之角笛 - 49167. */
    private QuestMagicAngleFlute() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        // 再生的圣所 1层-3层 - (王族)
        if (pc.isCrown() && (pc.getMapId() == 2000) && (pc.getX() == 32807)
                && (pc.getY() == 32773)) {
            boolean found = false;
            for (final L1Object obj : L1World.getInstance().getObject()) {
                if (obj instanceof L1MonsterInstance) {
                    final L1MonsterInstance mob = (L1MonsterInstance) obj;
                    if (mob != null) {
                        if (mob.getNpcTemplate().get_npcId() == 81323) {
                            found = true;
                            break;
                        }
                    }
                }
            }
            if (found) {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            } else {
                L1SpawnUtil.spawn(pc, 81323, 0, 0); // 神官奇诺 (新50级试炼怪-王族)
            }
        }

        // 再生的圣所 1层-3层 - (骑士)
        else if (pc.isKnight() && (pc.getMapId() == 2001)
                && (pc.getX() == 32807) && (pc.getY() == 32773)) {
            boolean found = false;
            for (final L1Object obj : L1World.getInstance().getObject()) {
                if (obj instanceof L1MonsterInstance) {
                    final L1MonsterInstance mob = (L1MonsterInstance) obj;
                    if (mob != null) {
                        if (mob.getNpcTemplate().get_npcId() == 81324) {
                            found = true;
                            break;
                        }
                    }
                }
            }
            if (found) {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            } else {
                L1SpawnUtil.spawn(pc, 81324, 0, 0); // 神官奇诺 (新50级试炼怪-骑士)
            }
        }

        // 再生的圣所 1层-3层 - (妖精)
        else if (pc.isElf() && (pc.getMapId() == 2002) && (pc.getX() == 32807)
                && (pc.getY() == 32773)) {
            boolean found = false;
            for (final L1Object obj : L1World.getInstance().getObject()) {
                if (obj instanceof L1MonsterInstance) {
                    final L1MonsterInstance mob = (L1MonsterInstance) obj;
                    if (mob != null) {
                        if (mob.getNpcTemplate().get_npcId() == 81325) {
                            found = true;
                            break;
                        }
                    }
                }
            }
            if (found) {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            } else {
                L1SpawnUtil.spawn(pc, 81325, 0, 0); // 神官奇诺 (新50级试炼怪-妖精)
            }
        }

        // 再生的圣所 1层-3层 - (法师)
        else if (pc.isWizard() && (pc.getMapId() == 2003)
                && (pc.getX() == 32807) && (pc.getY() == 32773)) {
            boolean found = false;
            for (final L1Object obj : L1World.getInstance().getObject()) {
                if (obj instanceof L1MonsterInstance) {
                    final L1MonsterInstance mob = (L1MonsterInstance) obj;
                    if (mob != null) {
                        if (mob.getNpcTemplate().get_npcId() == 81326) {
                            found = true;
                            break;
                        }
                    }
                }
            }
            if (found) {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            } else {
                L1SpawnUtil.spawn(pc, 81326, 0, 0); // 神官奇诺 (新50级试炼怪-法师)
            }
        } else {
            PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
        }
        pc.getInventory().consumeItem(49167, 1); // 删除魔之角笛
    }
}
